package com.inkegz.message.entity

import com.inkegz.message.utils.listEqual
import io.objectbox.annotation.Entity
import io.objectbox.annotation.Index
import io.objectbox.annotation.Unique
import io.objectbox.relation.ToMany
import io.objectbox.relation.ToOne

@Entity
class ConversationEntity: BaseEntity(){

    var versionId = 0L

    @Index
    @Unique
    var conversationKey = ""

    lateinit var messages: ToMany<MessageEntity>

    var rawString = ""

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        if (!super.equals(other)) return false

        other as ConversationEntity

        if (versionId != other.versionId) return false
        if (conversationKey != other.conversationKey) return false
        if (!listEqual(messages, other.messages)) return false
        if (rawString != other.rawString) return false

        return true
    }

    override fun hashCode(): Int {
        var result = super.hashCode()
        result = 31 * result + versionId.hashCode()
        result = 31 * result + conversationKey.hashCode()
        result = 31 * result + messages.hashCode()
        result = 31 * result + rawString.hashCode()
        return result
    }
}